import {createStore} from "vuex";
import axios from "axios";
const store= createStore({
    state(){
        return {
            //头部商品信息
            sellerInfo:{},
            //商品信息
            goodsInfo:[],
            //购物列表
            carList:[],
            // 玻璃特效
            show:false,
            price:0,
        }
    },
    mutations:{
      setSeller(state,payload){
         state.sellerInfo=payload.data;
      },
      setGoods(state,payload){
         state.goodsInfo=payload.data;
      },
      setCarList(state,payload){
         const isItem = state.carList.findIndex((item)=>{
            return item.name==payload.item.name;
         });
         if(isItem=="-1"){
            // console.log(payload)
            state.carList.push(payload.item);
            console.log(state.carList)
         }
        //  console.warn(state.carList)
      },
      showCar(state) {
        state.show = !state.show;
      },
    },
    actions:{
       async getSeller({commit}){
        const{data:{data}}=await axios.get("/api/seller");
        commit("setSeller",{data});
        
       },
       async getGoods({commit}){
        const {data:{data}} = await axios.get("/api/goods");
        commit("setGoods",{data});
      },
    },
      
});
export default store;